﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using ipListener;
using System.Net;

namespace ConsoleApplication1
{
    class Program
    {
        public static System.Timers.Timer t;
        public static string msg;
        public static string old_msg;
        public static ipListener.SendMail email;

        static void Main(string[] args)
        {
           t = new System.Timers.Timer(30000); //实例化Timer类，设置间隔时间为10000毫秒；   
            t.Elapsed += new System.Timers.ElapsedEventHandler(theout);  //到达时间的时候执行事件；   
            t.AutoReset = true;//设置是执行一次（false）还是一直执行(true)；   
            t.Enabled = true;  //是否执行System.Timers.Timer.Elapsed事件；  

            string hostname = System.Net.Dns.GetHostName();
            System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(hostname);
            msg += "========";
            msg = ipEntry.AddressList[0].ToString();
            foreach (IPAddress tmp in ipEntry.AddressList)
            {
                msg += "========";
                msg += tmp.ToString();
            }
            old_msg = msg;

            email = new SendMail("450618400@qq.com", "450618400@qq.com", msg, "ipChanged", "aikang5912881");
            email.Send();

            while(true){
                ;
            }
        }
        public static void theout(object source, System.Timers.ElapsedEventArgs e)
        {
            string hostname = System.Net.Dns.GetHostName();
            System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(hostname);
            msg += "========";
            msg = ipEntry.AddressList[0].ToString();
            foreach (IPAddress tmp in ipEntry.AddressList)
            {
                msg += "========";
                msg += tmp.ToString();
            }
            old_msg = msg;

            email = new SendMail("450618400@qq.com", "450618400@qq.com", msg, "ipChanged", "aikang5912881");
            email.Send();

        }  
    }
}
